<%include ../../inc/header.ejs%>
<!-- html主体代码 start -->

<fieldset class="layui-elem-field layui-field-title">
    <legend>角色权限分配</legend>
</fieldset>
<input value="<%=roleId%>" id="roleId" style="display: none;">
<form class="layui-form" id="data-form">
<% if(result.error ==0){%>
    <% result.data.forEach(function(menu){ %>
        <input type="checkbox" name="menu"
                <%if(menu.check==1){%> checked <%}%>
               value="<%=menu.id%>" title="<%=menu.name%>">
    <%})%>
<%}%>
</form>

<!-- html主体代码 end -->
<%include ../../inc/js.ejs%>
<!-- 私有脚本 start -->
<script>
    var form;
    $(function () {
        layui.use('form', function(){
            form = layui.form(); //只有执行了这一步，部分表单元素才会修饰成功

        });
    })
    function getVals() {
        var ids = [];
        $('#data-form').find('.layui-form-checked').each(function (i) {
            var pav = $(this).prev().val();
            ids.push(pav)

        })
        var vals = '';
        var roleId = $('#roleId').val();
        if(ids.length>0){
            for(var i=0;i<ids.length;i++){
                vals += '{roleId:'+roleId+',menuId:'+ids[i]+'},';
            }
            vals = '['+vals.substring(0,vals.length-1)+']';
        }
        //alert(vals)
        var data = {vals:vals};
        return data;
//        var param = {url:'/core/role/auth/1',data:data,type:'POST'};
//        var request = $.ajaxs(param);
//        request.done(function(d){
//            tips(d.message);
//        }).fail(function () {
//            tips("网络异常");
//        });
    }
</script>
<!-- 私有脚本 end -->
<%include ../../inc/footer.ejs%>